import 'package:flutter/material.dart';

class TabViewModel {
  String title;
  Widget widget;

  TabViewModel({
    this.title,
    this.widget,
  });
}

class Tabs extends StatelessWidget {
  final String title;
  final List<TabViewModel> demos;
  final bool tabScrollable;
  final TabController tabController;
  VoidCallback voidCallback;


  Tabs({
    this.title,
    this.demos,
    this.tabScrollable = true,
    this.tabController,
    this.voidCallback,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(this.title),
        actions: <Widget>[
          new IconButton(
              icon: new Icon(Icons.add),
              tooltip: '添加',
              onPressed: () {
                if(this.voidCallback!=null){
                  this.voidCallback();
                }
              }
          ),
        ],
        bottom: TabBar(
          controller: this.tabController,
          isScrollable: this.tabScrollable,
          tabs: this.demos.map((item) => Tab(text: item.title)).toList(),
          indicatorColor: Colors.white,
        ),
      ),
      body: TabBarView(
        controller: this.tabController,
        children: this.demos.map((item) => item.widget).toList(),
      ),
    );
  }
}